package thread;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import convert.Util;

public class TestThread {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		long beginTime = System.currentTimeMillis();
		ExecutorService exec = Executors.newCachedThreadPool();
		String startDate = "2016-01-01";
		String endDate = "2016-03-16";
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date date;
		try {
			date = sdf.parse(startDate);
			Date date1 = sdf.parse(endDate);
			List<String> urls = Util.getUrlsByDate(date, date1);
			for (int i = 0; i < 5; i++)
				exec.execute(new XMLConvertTask(urls));
			exec.shutdown();
			while (true) {
				if (exec.isTerminated()) {
					for (int i = 0; i < XMLConvertTask.getTimestamp().size(); i++) {
//						System.out.println(XMLConvertTask.getTimestamp().get(i)
//								+"||"+ XMLConvertTask.getSettlement1().get(i)
//								+"||"+  XMLConvertTask.getSettlement2().get(i)
//								+ "||"+ XMLConvertTask.getSettlement3().get(i)
//								+ "||"+ XMLConvertTask.getSettlement4().get(i)
//								+ "||"+ XMLConvertTask.getSettlement5().get(i));
					}
					System.out.println(System.currentTimeMillis()-beginTime);
					break;
				}
//				Thread.sleep(100);
			}

		} catch (ParseException e) {
			e.printStackTrace();
		} 
//		catch (InterruptedException e) {
//			e.printStackTrace();
//		}

	}

}
